package cn.sf.sufinguserconsumer.controller;

import cn.sf.pojo.User;
import cn.sf.sufinguserconsumer.service.QueryUserService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
@RestController
public class QueryUserController {

    @Resource
    private QueryUserService  queryUserService;

    @RequestMapping("/queryUserDL")
    public String queryUser(String userName, String userPassword ) {
        User user=queryUserService.queryUser(userName,userPassword);
        if(user!=null){
            return "登录成功";
        }else{
            return "登录失败";
        }

    }

    @RequestMapping("/queryUserEmailDL")
    public  String queryUserEmail(String userEmail, String userPassword, HttpSession session){
        System.out.println("userEmail:"+userEmail);
        User user = queryUserService.queryUserEmail(userEmail, userPassword);
        if(user!=null){
            session.setAttribute("user",user);
            return "登录成功，跳转首页";
        }else{
            return "登录失败,重新登录";
        }
    }



    //注册
    @RequestMapping("/userAddDL")
    public String userAdd(User user, HttpSession session){
        System.out.println("name:"+user.getUserCode());
        int count = queryUserService.userAdd(user);
        if (count>0) {  //班级添加学员成功
            session.setAttribute("user", user);
            return "到达登录页面";
        }else if (count>1){
            return  "到注册页面";
        }else {
            return "到注册页面";
        }

    }







}
